/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javaseapp - Thread1
 * <p>Powered by webrx On 2021-08-23 17:44:19
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Thread1 {
    public static void main(String[] args) {
        //多线程 方法一 继承Thread
        var t1 = new Thread() {
            @Override
            public void run() {
                this.setName("one thread");
                System.out.println(this.getName());
                System.exit(0);
            }
        };
        t1.setName("one1111 thread");
        t1.start();

        //多线程 方法二 实现接口，实现Thread作为参数
        var t2 = new Runnable() {
            @Override
            public void run() {
                String n = Thread.currentThread().getName();
                System.out.println(n);
                System.exit(0);
            }
        };
        var t22 = new Thread(t2, "two thread");
        t22.setName("two2222 thread");
        t22.start();

        //main线程输出
        try {
            TimeUnit.SECONDS.sleep(2);
            Thread.currentThread().setName("main thread");
            System.out.println(Thread.currentThread().getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
